<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="layuimini/css/public.css" media="all">
    <script src="layuimini/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">

    <form id="box-form" class="layui-form" action="">

        <div class="layui-form-item" lay-filter="login-filter" style="width: 50%">
            <label class="layui-form-label">客户编号</label>
            <div class="layui-input-block">
                <input placeholder="请输入需要发送消息的客户编号" type="text" name="customId" value="" class="layui-input">
                <div class="layui-form-mid layui-word-aux">填写客户编号，发送多个客户需要添加"、"，例：360001、360002</div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text" style="width: 50%;">
            <label class="layui-form-label">输入发送的消息内容</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" name="content" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="log-btn" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">点击发送</button>
                <button type="reset" class="layui-btn layui-btn-primary">清空内容</button>
            </div>
        </div>
    </form>
</div>

<script>
    layui.use(['layer' , 'form' , 'layarea' , 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate,
            layarea = layui.layarea,
            $ = layui.$;

        //地区选择控件
        layarea.render({
            elem: '#area-picker',
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            //这里需要转为JSON格式
            var da = JSON.stringify(data.field);

            $("#log-btn").attr("disabled","disabled").addClass("layui-btn-disabled");

            $.ajax({
                //注意：这里需要添加/
                url:"/email/sendEmail",
                method: "post",
                data: da,
                contentType: "application/json;charset=UTF-8",   // 注意：这里需要设置请求头，因为springmvc中默认接收的请求头为这个
                dataType: "json",
                success: function (res){
                    if(res.code == 0){
                        layer.msg("发送成功",{ icon: 6,time: 2000,anim: 5},function (){
                            $("#log-btn").removeAttr("disabled","disabled").removeClass("layui-btn-disabled");
                        });
                    }else{
                        $("#log-btn").removeAttr("disabled","disabled").removeClass("layui-btn-disabled");
                        layer.msg(res.msg,{ icon: 2,time: 1000,anim: 6});
                    }

                    form.val("login-filter",{
                        "customId" : "",
                        "content" : ""
                    })
                }
            })
            // // 关闭弹出层
            // layer.close(index);

            return false;
        });

    });
</script>
</body>
</html>